package com.smedi.ismedi.inmail.core.port.adapter.restful;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.smedi.ismedi.inmail.api.dto.request.LoginLogLoginRequest;
import com.smedi.ismedi.inmail.api.dto.request.LoginLogLogoutRequest;
import com.smedi.ismedi.inmail.api.dto.request.LoginLogPageRequest;
import com.smedi.ismedi.inmail.api.dto.response.LoginLogResponse;
import com.smedi.ismedi.inmail.api.feign.RemoteLoginLogFeignApi;
import com.smedi.ismedi.inmail.core.application.command.LoginLogLoginCommand;
import com.smedi.ismedi.inmail.core.application.command.LoginLogLogoutCommand;
import com.smedi.ismedi.inmail.core.application.command.LoginLogPageCommand;
import com.smedi.ismedi.inmail.core.application.query.LoginLogQueryService;
import com.smedi.ismedi.inmail.core.application.service.LoginLogApplicationService;
import com.smedi.ismedi.inmail.core.domain.aggregatemodel.LoginLog;
import com.smedi.ismedi.inmail.core.port.adapter.convert.AdapterConverter;
import com.smedi.ismedi.web.starter.common.PaginationData;
import com.smedi.ismedi.web.starter.common.ResponseData;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.RestController;

/**
 * 通知公告Controller
 *
 * @author jiangqinxuan
 * @date 2021/07/26
 */
@AllArgsConstructor
@RestController
public class LoginLogController implements RemoteLoginLogFeignApi {
    private final LoginLogApplicationService loginLogApplicationService;
    private final LoginLogQueryService loginLogQueryService;
    private final AdapterConverter adapterConverter;

    @Override
    public ResponseData<Long> login(LoginLogLoginRequest loginLogLoginRequest) {
        LoginLogLoginCommand loginLogLoginCommand = adapterConverter.loginLogLoginRequestToLoginLogLoginCommand(loginLogLoginRequest);
        return new ResponseData<>().success(loginLogApplicationService.login(loginLogLoginCommand));
    }

    @Override
    public ResponseData<Boolean> logout(LoginLogLogoutRequest loginLogLogoutRequest) {
        LoginLogLogoutCommand loginLogLogoutCommand = adapterConverter.loginLogLogoutRequestToLoginLogLogoutCommand(loginLogLogoutRequest);
        loginLogApplicationService.logout(loginLogLogoutCommand);
        return new ResponseData<>().success(true);
    }

    @Override
    public ResponseData<PaginationData<LoginLogResponse>> page(LoginLogPageRequest loginLogPageRequest) {
        LoginLogPageCommand loginLogPageCommand = adapterConverter.loginLogPageRequestToLoginLogPageCommand(loginLogPageRequest);
        Page<LoginLog> loginLogPage = loginLogQueryService.page(loginLogPageCommand);
        return new ResponseData<>().success(adapterConverter.loginLogPageToLoginLogResponsePaginationData(loginLogPage));
    }
}
